package servlet;

import static org.junit.Assert.assertEquals;

import java.sql.SQLException;
import java.util.ArrayList;

import modele.Formation;

import org.junit.Test;

import servlets.RechercherFormation;
import servlets.RechercherFormation.Container;
import dao.AgriotesDbTestCase;
import dao.FormationDAO;

public class RechercherFormationTest extends AgriotesDbTestCase {

	@Test
	public void testRechercherFormation() throws SQLException {

		RechercherFormation rf = new RechercherFormation();

		boolean rechercheParTheme = false;
		String rechercheText = "BEP agricole option Aménagement de l’espace";

		Formation formation = FormationDAO.lireParTitre(rechercheText);

		ArrayList<Container> containerList = rf.getContainerList(rechercheText, rechercheParTheme);

		for (Container container : containerList) {
			assertEquals(formation, container.getFormation());
		}
	}

	@Test
	public void testRechercherFormation2() throws SQLException {

		RechercherFormation rf = new RechercherFormation();

		boolean rechercheParTheme = false;
		String rechercheText = "ECO";

		Formation formation = FormationDAO.lireParCode(rechercheText);

		ArrayList<Container> containerList = rf.getContainerList(rechercheText, rechercheParTheme);

		for (Container container : containerList) {
			assertEquals(formation, container.getFormation());
		}
	}

}
